package com.wx.springboot.step9back.controller;

import com.wx.springboot.step9back.common.api.CommonResult;
import com.wx.springboot.step9back.model.LoginInfo;
import com.wx.springboot.step9back.model.Page;
import com.wx.springboot.step9back.service.LoginInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/loginInfo")
public class LoginInfoController {

    @Autowired
    private LoginInfoService loginInfoService;

    @GetMapping("/getSelectList")
    public CommonResult getSelectList(@RequestParam Map<String, Object> data){
        HashMap<String, Object> map = new HashMap<>();
        List<LoginInfo> loginInfos = loginInfoService.getSelectList(data);
        int count = loginInfoService.getSelectCount(data);
        Page page = new Page();
        page.setList(loginInfos);
        page.setTotal(count);
        map.put("list",loginInfos);
        map.put("count",count);
        return CommonResult.success(map);
    }

    @GetMapping("/getLoginInfoById")
    public CommonResult getLoginInfoById(@RequestParam Integer id){
        HashMap<String, Object> map = new HashMap<>();
        LoginInfo loginInfo = loginInfoService.getLoginInfoById(id);
        map.put("data",loginInfo);
        return CommonResult.success(map);
    }

    @PostMapping("/delLoginInfo")
    public CommonResult delLoginInfo(@RequestBody LoginInfo loginInfo){
        HashMap<String, Integer> map = new HashMap<>();
        int result = loginInfoService.delLoginInfo(loginInfo);
        map.put("result",result);
        return CommonResult.success(map);
    }

    @PostMapping("/batchDeletion")
    public CommonResult batchDeletion(@RequestParam List<Integer> ids){
        HashMap<String, Object> map = new HashMap<>();
        String result = loginInfoService.batchDeletion(ids);
        map.put("data",result);
        return CommonResult.success(map);
    }

}
